<?php

class action
{
	var $actions		='';
	var $temaplate		='';
	var $cacheId		='';
	var $view			='';
	var $model			='';

	function __construct()
	{
		S::instance(APP.'Action');
		$this->view=new template();
		$theme=S::get('theme')?S::get('theme'):S::get('defaultTheme');
		$this->view->templateDir='themes/'.$theme.'/';
		$this->view->cacheDir='temp/'.S::get('cachePath').'/';
		$this->view->compliedDir='temp/'.S::get('compliedPath').'/';
		foreach($this->actions as $k => $v)
		{
			if($k==S::get('__actionName'))
			{
				$this->temaplate=$v['template']?$v['template']:$this->defaultTemaplte();
				if(!$v['uncache'])
				{
					$this->cacheId=$v['cacheId']?$v['cacheId']:$this->defaultCacheId();
				}
				break;
			}
		}
	}

	function isCache()
	{
		return $this->view->isCache($this->temaplate,$this->cacheId);
	}

	function display()
	{
		if(!$this->isCache())
		{
			$action=S::get('__action');
			$this->$action();
		}
		$this->view->display($this->temaplate,$this->cacheId);
	}

	function assign($key,$value)
	{
		$this->view->assign($key, $value);
	}



	function defaultTemaplte()
	{
		$filename=S::get('__moduleName')."_".S::get('__actionName').".html";
		return $filename;
	}

	function defaultCacheId()
	{
		$cacheId=S::get('__Rs');
		return sprintf('%X', crc32($cacheId));
	}



	function error()
	{

	}

	function warn()
	{

	}

	function success()
	{

	}




}
?>